package com.youfang.sixthmedia.message;

import java.util.List;

import org.json.JSONObject;

import com.gzit.utils.AndroidUtils;
import com.youfang.sixthmedia.net.MessageDelegate;
import com.youfang.sixthmedia.net.Pair;
import com.youfang.sixthmedia.net.Request;
import com.youfang.sixthmedia.net.Response;

public class VersionMessageDelegate extends MessageDelegate {

	public static class Req extends Request {

		@Override
		public List<Pair> getParams() {
			return Pair.EMPTY_PAIRS;
		}

		@Override
		public void genMetaData() {
			this.setActionPath("/version/android.txt");
		}

	}

	public static class Resp extends Response {

		private String version;
		private String marketurl;
		private String download;

		public boolean needDownload() {
			if (!AndroidUtils.System.getVersionName().equals(version)) {
				return true;
			}
			return false;
		}

		@Override
		protected void decodeBody(JSONObject bodyJSON) throws Exception {

			version = getString(bodyJSON, "version");
			marketurl = getString(bodyJSON, "marketurl");
			download = getString(bodyJSON, "download");

			// test...
//			download = "http://3g.kingdee.com:6899/3ginfo/download?file=EC232.apk";

		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public String getMarketurl() {
			return marketurl;
		}

		public void setMarketurl(String marketurl) {
			this.marketurl = marketurl;
		}

		public String getDownload() {
			return download;
		}

		public void setDownload(String download) {
			this.download = download;
		}

	}

	public Req req = new Req();
	public Resp resp = new Resp();

	@Override
	public Request request() {
		return req;
	}

	@Override
	public Response response() {
		return resp;
	}

}
